package com.imooc.product.converter;

import com.imooc.product.common.ProductInfoOutput;
import com.imooc.product.dataobject.ProductInfo;
import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * ProductInfo2OutputConverter
 *
 * @author leon.cheng
 * @date 2018/12/11 11:29
 **/
public class ProductInfo2OutputConverter {
    public static ProductInfoOutput convert(ProductInfo productInfo)
    {
        ProductInfoOutput productInfoOutput=new ProductInfoOutput();
        if(productInfo!=null)
        {
            BeanUtils.copyProperties(productInfo,productInfoOutput);
        }
        else
        {
            productInfoOutput=null;
        }
        return productInfoOutput;
    }
    public static List<ProductInfoOutput> converts(List<ProductInfo> productInfoList)
    {
        List<ProductInfoOutput> productInfoOutputList=new ArrayList<>();
        if(!ArrayUtils.isEmpty(productInfoList.toArray()))
        {
            for (ProductInfo productInfo : productInfoList) {
                productInfoOutputList.add(convert(productInfo));
            }
        }
        return productInfoOutputList;
    }
}
